package com.ars.common.servlet.client;

import com.ars.common.beans.Active.Active;
import com.ars.common.dao.FindActiveInformation;
import com.ars.common.dao.activity.FindActivityByType;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;
import java.util.TreeMap;

/**
 * ClassName: FindActivityByTypeServlet
 * Package: com.ars.common.servlet.client.activity
 * Description:
 *
 * @Author: Bryan Long
 * @Create: 2024/8/8 - 14:52
 * @Version: v1.0
 */

@WebServlet("/FindActivityByTypeServlet")
public class FindActivityByTypeServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        System.out.println("FindActiveByType Test");

        // get type from request
        String type = request.getParameter("type");
        switch (type){
            case "1": type="文艺体育";break;
            case "2": type="社会实践";break;
            case "3": type="思想成长";break;
            case "4": type="劳动实践";break;
            case "5": type="创新创业";break;
            case "6": type="工作履历";break;
            default:break;
        }
        System.out.println(type);

        //将活动信息发送到查询界面
        TreeMap<Integer, Active> tmap = new TreeMap<Integer,Active>();
        try {
            tmap = new FindActivityByType().findActivityByType(type);
        } catch (SQLException | ClassNotFoundException throwables) {
            throwables.printStackTrace();
        }
        request.setAttribute("actInfo",tmap);
        request.getRequestDispatcher("/indexFace/findActive.jsp").forward(request, response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }
}
